<template>
  <div>
    <el-dialog title="上架失败类目列表" :visible.sync="open" width="70%" append-to-body @close="cancel">
      <!--      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">-->
      <!--        <el-form-item label="产品ID" prop="aeProductId">-->
      <!--          <el-input v-model="queryParams.aeProductId" placeholder="请输入产品id" clearable/>-->
      <!--        </el-form-item>-->
      <!--        <el-form-item>-->
      <!--          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
      <!--          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      <!--        </el-form-item>-->
      <!--      </el-form>-->
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" :disabled="multiple" @click="handleDelete">批量删除</el-button>
        </el-col>
      </el-row>
      <!--  类目列表  -->
      <el-table v-loading="loading" :data="categoryList" border stripe @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column label="店铺别名" prop="storeAlias" align="center"/>
        <el-table-column label="类目ID" prop="categoryId" align="center"/>
        <el-table-column label="类目名称" prop="categoryName" align="center"/>
        <el-table-column label="创建时间" prop="createTime" align="center"/>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getCategoryList"/>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {queryGroundCategoryList, deleteGroundCategory} from "@/api/autoOperation/ground";

export default {
  name: "categoryList",
  props: {
    storeId: {
      type: String,
      default: undefined,
    }
  },
  data() {
    return {
      loading: false,
      showSearch: true,
      open: true,
      autoConfigValue: "0",
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        storeId: this.storeId
      },
      categoryList: [],//自运营店铺列表
      total: 0,//数据总条数
      timeRange: "",// 时间范围
      ids: "",
      single: true,
      multiple: true
    }
  },
  created() {
    this.getCategoryList()
  },
  methods: {
    getCategoryList() {
      this.loading = true
      queryGroundCategoryList(this.queryParams).then(res => {
        this.loading = false
        let data = res.data
        this.categoryList = data.list
        this.total = data.total
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    // 删除类目
    handleDelete(row) {
      const id = row.id || this.ids.toString();
      this.$confirm("是否确定删除此类目？", '提示').then(() => {
        deleteGroundCategory({id: id}).then(res => {
          this.$message.success(res.msg)
          this.getCategoryList()
        })
      })
    },
    cancel() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>

</style>
